const XLSX = require('xlsx');
const path = require('path');
const fs = require('fs');

// 示例用户数据
const users = [
  { username: 'admin', password: '123456' },
  { username: 'user1', password: 'password123' },
  { username: 'test', password: 'test123' }
];

// 创建工作簿
const workbook = XLSX.utils.book_new();

// 创建工作表
const worksheet = XLSX.utils.json_to_sheet(users);

// 将工作表添加到工作簿
XLSX.utils.book_append_sheet(workbook, worksheet, 'Users');

// 确保 data 目录存在
const dataDir = path.join(__dirname, '..', 'data');
if (!fs.existsSync(dataDir)) {
  fs.mkdirSync(dataDir);
}

// 写入文件
XLSX.writeFile(workbook, path.join(dataDir, 'users.xlsx'));

console.log('用户数据文件已创建在 data/users.xlsx'); 